package com.qingyi.mall.coupon.controller;

import java.util.Arrays;
import java.util.Map;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.qingyi.mall.coupon.entity.PmsAttrEntity;
import com.qingyi.mall.coupon.service.PmsAttrService;
import com.qingyi.mall.common.utils.PageUtils;
import com.qingyi.mall.common.utils.R;



/**
 * 商品属性
 *
 * @author qingyi
 * @email qingyi@gmail.com
 * @date 2020-07-12 19:59:59
 */
@RestController
@RequestMapping("coupon/pmsattr")
@Api(tags = "商品属性")
public class PmsAttrController {
    @Autowired
    private PmsAttrService pmsAttrService;

    /**
     * 列表
     */
    @RequestMapping(value = "/list",method = RequestMethod.GET)
    @ApiOperation(value = "获取列表",notes = "获取商品属性的列表")
    //@RequiresPermissions("coupon:pmsattr:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = pmsAttrService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping(value = "/info/{attrId}",method = RequestMethod.GET)
    @ApiOperation(value = "信息",notes = "获取商品属性的信息")
    //@RequiresPermissions("coupon:pmsattr:info")
    public R info(@PathVariable("attrId") Long attrId){
		PmsAttrEntity pmsAttr = pmsAttrService.getById(attrId);

        return R.ok().put("pmsAttr", pmsAttr);
    }

    /**
     * 保存
     */
    @RequestMapping(value = "/save",method = RequestMethod.POST)
    @ApiOperation(value = "保存",notes = "保存商品属性的信息")
    //@RequiresPermissions("coupon:pmsattr:save")
    public R save(@RequestBody PmsAttrEntity pmsAttr){
		pmsAttrService.save(pmsAttr);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping(value = "/update",method = RequestMethod.PUT)
    @ApiOperation(value = "修改",notes = "修改商品属性的信息")
    //@RequiresPermissions("coupon:pmsattr:update")
    public R update(@RequestBody PmsAttrEntity pmsAttr){
		pmsAttrService.updateById(pmsAttr);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping(value = "/delete",method = RequestMethod.DELETE)
    @ApiOperation(value = "修改",notes = "修改商品属性的信息")
    //@RequiresPermissions("coupon:pmsattr:delete")
    public R delete(@RequestBody Long[] attrIds){
		pmsAttrService.removeByIds(Arrays.asList(attrIds));

        return R.ok();
    }

}
